package com.supostacks.xuetangerp.server.oss;

import com.aliyun.oss.ClientBuilderConfiguration;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyuncs.exceptions.ClientException;

public class AliyunOssConfig {
    public static final String ENDPOINT = "oss-cn-beijing.aliyuncs.com";
    public static final String BUCKET_NAME = "fuyexuetang";
    public static final String REGION = "cn-beijing";
    public static final Long EXPIRATION_TIME = 3600L;

    public static OSS getOssClient() {
        try {
            EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.
                    newEnvironmentVariableCredentialsProvider();

            ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
            clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);

            return OSSClientBuilder.create()
                    .endpoint(ENDPOINT)
                    .credentialsProvider(credentialsProvider)
                    .clientConfiguration(clientBuilderConfiguration)
                    .region(REGION)
                    .build();
        } catch (ClientException e) {
            throw new RuntimeException(e);
        }

    }

}
